package schudel.daniel.androidspellingquiz;

import java.util.ArrayList;
import java.util.Collections;

import android.app.Application;
import android.util.Log;

public class SpellingQuizApplication extends Application {
    private ArrayList<String> currentSpellingWords;
    private ArrayList<String> spellingAnswers;
    private String            currentSpellingListName;
    private static final String TAG = "SQApplication: ";
    
    public String getCurrentListName() {
    	return currentSpellingListName;
    }
    
    public ArrayList<String> getCurrentWords() {
	    return currentSpellingWords;
    }

    public ArrayList<String> getAnswers () {
	    return spellingAnswers;
    }

	@Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate");
        currentSpellingWords = new ArrayList<String>();
        spellingAnswers = new ArrayList<String>();
    }
	
    public boolean prepNewQuiz(String listIdentifier) {
        currentSpellingListName = listIdentifier;
		
        spellingAnswers.clear();
        currentSpellingWords.clear();
		
		// lookup listIdentifier and populate currentSpellingWords
        DB db = new DB(this);
        ArrayList<String> all = db.getWords(listIdentifier);
        if (all.size() == 0) {
        	return false;
        } else {
            Collections.shuffle(all);
            currentSpellingWords.addAll(all);
            return true;
        }
    }
	
    public String getCurrentWord() {
        int c = spellingAnswers.size();
        return currentSpellingWords.get(c);
    }
	
    // return true if end of quiz
    public boolean addGuess(String guess) {
        spellingAnswers.add(guess);
        return (spellingAnswers.size() == currentSpellingWords.size());
    }
	

    
    public int wordsInCurrentQuiz() {
    	return currentSpellingWords.size();
    }

    public int indexInCurrentQuiz() {
        return spellingAnswers.size();
    }
}
